home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
bin2snd
/
bin2snd.c
next >
Wrap
C/C++ Source or Header
|
1994-11-13
|
4KB
|
149 lines
/* バイナリファイルをSNDファイルに変換するツール by Ushio */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct
{
char name[8];
unsigned long id;
unsigned long length;
unsigned long looppoint;
unsigned long looplength;
unsigned short freq;
unsigned short adjust;
unsigned char note;
unsigned char reserve1;
unsigned short reserve2;
} SNDBUF;
unsigned int Freq = 20*0x62;
char Filename_bin[256]="";
char Filename_snd[256]="";
int fexist( char *fn )
{
FILE *fp;
if ( (fp = fopen( fn,"r" )) == NULL )
return 0;
fclose(fp);
return 1;
}
long fsize( char *fn )
{
FILE *fp = fopen( fn,"rb" );
long size, save = ftell( fp );
if ( fseek( fp, 0, SEEK_END ) != 0 ) { fclose(fp); return -1; }
if ( (size = ftell( fp )) < 0 ) { fclose(fp); return -1; }
if ( fseek( fp, save, SEEK_SET ) != 0 ) { fclose(fp); return -1; }
fclose(fp);
return size;
}
int arg( int argc, char *argv[] )
{
int i;
char sw, *para;
char *p;
if ( argc < 2 )
return 1;
for ( i=1; i<argc; i++ ) {
if ( argv[i][0]!='-' && argv[i][0]!='/' ) {
if ( Filename_bin[0] == '\0' )
strcpy(Filename_bin,argv[i]);
else if ( Filename_snd[0] == '\0' )
strcpy(Filename_snd,argv[i]);
else
return 4;
} else {
sw = argv[i][1];
if ( sw!='\0' && argv[i][2]!='\0' ) {
para = argv[i] + 2;
} else {
if ( i<argc )
para = argv[++i];
else
para = "";
}
printf("i=%d,sw=%d(%c),para='%s'\n",i,sw,sw,para);
switch ( sw ) {
case 'h': case 'H': case '?':
return 'h';
case 'f': case 'F':
Freq = atof( para ) * 0x62;
if ( Freq<0 || 20*0x62<Freq ) {
fprintf(stderr," 周波数が不正です(%u).\n",Freq/0x62);
return 'f';
}
break;
default:
fputs(" 不正なパラメーターです.\n",stderr);
return 2;
}
}
}
if (Filename_bin[0]=='\0') {
fputs(" ファイルを指定してください.\n",stderr);
return 3;
}
if (Filename_snd[0]=='\0') {
strcpy( Filename_snd, Filename_bin );
p = strrchr( Filename_snd, '.' ) ;
if ( p==NULL || p[1]=='\\' )
p = Filename_snd + strlen(Filename_snd) ;
strcpy( p, ".snd" );
}
if ( stricmp( Filename_bin, Filename_snd ) == 0 ) {
fputs(" 同名のファイルです.\n",stderr);
return 5;
}
return 0;
}
int main( int argc, char *argv[] )
{
FILE *fp;
SNDBUF buf;
char comstr[256];
if ( arg(argc,argv)!=0 ) {
fputs("\nバイナリファイルをSNDファイルに変換するツール by Ushio.",stderr);
fputs("\n Use : bin2snd [-f freq(kHz)] BINfile [SNDfile]\n",stderr);
return 1;
}
printf("Filename_bin='%s',Filename_snd='%s'\n",Filename_bin,Filename_snd);
if ( ! fexist(Filename_bin) ) {
printf("\n \"%s\" がオープン出来ません.",Filename_bin);
return 1;
}
if ( (fp=fopen(Filename_snd,"wb"))==NULL ) {
printf("\n \"%s\" がオープン出来ません.",Filename_snd);
return 1;
}
buf.name[0] ='\0';
buf.id = 0;
buf.length = fsize(Filename_bin);
buf.looppoint = 0;
buf.looplength = 0;
buf.freq = Freq;
buf.adjust = 0;
buf.note = 60;
if ( fwrite(&buf, sizeof(buf), 1, fp)<1 ) {
fprintf(stderr,"\n \"%s\" を書き込めません(data).",Filename_snd);
fclose(fp);
return 1;
}
fclose(fp);
printf("freqency %lu\n",buf.freq*0x64);
printf("length %#010x %16lu\n",buf.length,buf.length);
sprintf(comstr,"copy /b %s+%s %s > nul",Filename_snd,Filename_bin,Filename_snd);
puts( comstr );
system( comstr );
return 0 ;
}